package com.hopechart.micro.runner;

import com.hopechart.micro.common.exception.BusinessException;
import com.hopechart.micro.domain.cache.GpsCache;
import com.hopechart.micro.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

/**
 * <p>
 *     <br/>启动前置操作类
 * </p>
 * @author daijiang@hopechart.com
 * @date 2017-10-30 09:44:19
 * @copyright 杭州鸿泉数字设备有限公司
 * @version V1.0.0
 */
public class StartRunner implements CommandLineRunner{

    private static Logger LOG = LoggerFactory.getLogger(StartRunner.class);

    @Autowired
    private GpsCache gpsCache;

    @Override
    public void run(String... strings) throws Exception {
        try {
            LOG.info("Micro Service start.");
            initCache();
        } catch (BusinessException e) {
            LOG.error(e.getMessage());
            System.exit(-1);
        }

    }

    private void initCache() {
        LOG.info("GPS数据缓存开始");
        Object gps = gpsCache.get("gps");
        LOG.info(JsonUtil.toString(gps));
        LOG.info("GPS数据缓存结束");
    }
}
